import React from "react";
import {Button, Table, Tag} from "antd";
import {Link, useNavigate} from "react-router-dom";

const publishStateList= ["未发布","已发布","已下线"];
const colorList= ['orange', 'green', 'red'];

export default function NewsPublish(props) {

    // const navigate= useNavigate();

    const columns = [
        {
            title: '新闻标题',
            dataIndex: 'title',
            render: (title, record)=>{
                // return <a href={"#/news-manage/preview/" + record.id}>{title}</a>
                return <Link to={"/news-manage/preview/" + record.id}>{title}</Link>
                // return <div style={{color:"#1890ff", cursor: "pointer"}} onClick={()=>navigate("/news-manage/preview/"+ record.id)}>{title}</div>
            }
        },
        {
            title: '作者',
            dataIndex: 'author'
        },
        {
            title: '新闻分类',
            dataIndex: 'category',
            render: (category)=>category.title
        },
        {
            title: '发布状态',
            dataIndex: 'publishState',
            render: (publishState)=><Tag color={colorList[publishState]}>{publishStateList[publishState]}</Tag>
        },
        {
            title: '操作',
            key: 'operation',
            render: (record) => {
                /*if(record.publishState===0) {
                    return <Button type="primary">发布</Button>
                } else if(record.publishState===1) {
                    return <Button danger>下线</Button>
                } else if(record.publishState===2) {
                    return <Button type="dashed">审核</Button>
                }*/
                return props.button(record.id);
            },
        }
    ];


    return (
        <Table dataSource={props.dataSource} columns={columns} pagination={{ pageSize: 5 }} rowKey={ item=>item.id }/>
    )
}

